package com.baizhi.service.impl;

import com.baizhi.entity.BzLog;
import com.baizhi.mapper.BzLogMapper;
import com.baizhi.service.BzLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yu
 */
@RestController
public class BzLogServiceImpl implements BzLogService {
    @Autowired
    private BzLogMapper bzLogMapper;
    @Override
    public Map showAll(String query, Integer pageNum, Integer pageSize) {
        HashMap<String, Object> map = new HashMap<>();
        QueryWrapper<BzLog> queryWrapper=new QueryWrapper<>();
        if(query!=null){
            queryWrapper.like("username",query).or().like("operation",query).or().like("request_method",query).or().like("ip_address",query).or().like("create_date",query).or().like("description",query);
        }
        Page<BzLog> bzLogPage = new Page<>(pageNum, pageSize);
        Page<BzLog> selectPage = bzLogMapper.selectPage(bzLogPage, queryWrapper);
        long total = selectPage.getTotal();
        List<BzLog> records = selectPage.getRecords();
        map.put("code",0);
        map.put("count",total);
        map.put("data",records);
        return map;
    }
}
